#include <iostream>
#include <string>
#include "TcpServer.hpp"
#include "Http.hpp"
void Usage(std::string proc)
{
    std::cerr << "Usage : " << proc << " serverip serverport" << std::endl;
}

std::string testHTTP(std::string &requeststr)
{
    std::cout << "########################" << std::endl;
    std::cout << requeststr << std::endl;
    std::cout << "########################" << std::endl;

    std::string respone = "HTTP/1.1 200 OK\r\n\r\n";

    respone += "<!DOCTYPE html>\r\n<html>\r\n<head>\r\n\
                <title>Hello World</title>\r\n</head>\r\n<body>\r\n\
                <h1>Hellp World</h1>\r\n</body>\r\n</html>";
    return respone;
}


// ./http serverport
int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        Usage(argv[0]);
        exit(0);
    }
    uint16_t serverport = std::stoi(argv[1]);

    EnableConsoleLogStrategy();
    // EnableFileLogStrategy();
    // 1. 协议
    std::unique_ptr<Http> http = std::make_unique<Http>();
    
    // 2. 网络
    std::unique_ptr<Tcpserver> tcpsock = std::make_unique<Tcpserver>(serverport,[&http](std::string &reqstr)->std::string{
        return http->HandlerRequest(reqstr);
    });
    tcpsock->Run();

    while (true)
    {
    }

    return 0;
}